<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: dark)"><meta name="generator" content="Hexo 6.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/hexo/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/hexo/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/hexo/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/hexo/images/logo.svg" color="#222">

<link rel="stylesheet" href="/hexo/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css" integrity="sha256-Z1K5uhUaJXA7Ll0XrZ/0JhX4lAtZFpT6jkKrEDT0drU=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/blue/pace-theme-bounce.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous"></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"codeleader.gitee.io","root":"/hexo/","images":"/hexo/images","scheme":"Gemini","darkmode":true,"version":"8.14.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/hexo/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/hexo/js/config.js"></script>

    <meta name="description" content="1、Java基础 &#x3D;&#x3D;，equals和hashCode的区别  &#x3D;&#x3D;:对于基本数据类型,&#x3D;&#x3D;比较的是值，对于引用数据类型，&#x3D;&#x3D;比较的是内存地址。 equals:对于没有重写equals方法的类，equals方法和&#x3D;&#x3D;作用类似；对于重写过equals方法的类，equals比较的是值。">
<meta property="og:type" content="article">
<meta property="og:title" content="Java基础知识复习">
<meta property="og:url" content="https://codeleader.gitee.io/hexo/2023/07/08/Java%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E5%A4%8D%E4%B9%A0/index.html">
<meta property="og:site_name" content="CodeLeader">
<meta property="og:description" content="1、Java基础 &#x3D;&#x3D;，equals和hashCode的区别  &#x3D;&#x3D;:对于基本数据类型,&#x3D;&#x3D;比较的是值，对于引用数据类型，&#x3D;&#x3D;比较的是内存地址。 equals:对于没有重写equals方法的类，equals方法和&#x3D;&#x3D;作用类似；对于重写过equals方法的类，equals比较的是值。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://codeleader.oss-cn-beijing.aliyuncs.com/site/image-20230629100728692.png">
<meta property="og:image" content="https://codeleader.oss-cn-beijing.aliyuncs.com/site/image-20230706111234138.png">
<meta property="og:image" content="https://codeleader.oss-cn-beijing.aliyuncs.com/site/image-20230706112049155.png">
<meta property="article:published_time" content="2023-07-08T09:14:05.000Z">
<meta property="article:modified_time" content="2023-07-08T10:01:55.753Z">
<meta property="article:author" content="别团等shy哥发育">
<meta property="article:tag" content="Java">
<meta property="article:tag" content="面试">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://codeleader.oss-cn-beijing.aliyuncs.com/site/image-20230629100728692.png">


<link rel="canonical" href="https://codeleader.gitee.io/hexo/2023/07/08/Java%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E5%A4%8D%E4%B9%A0/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://codeleader.gitee.io/hexo/2023/07/08/Java%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E5%A4%8D%E4%B9%A0/","path":"2023/07/08/Java基础知识复习/","title":"Java基础知识复习"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>Java基础知识复习 | CodeLeader</title>
  








  <noscript>
    <link rel="stylesheet" href="/hexo/css/noscript.css">
  </noscript>
<style>mjx-container[jax="SVG"] {
  direction: ltr;
}

mjx-container[jax="SVG"] > svg {
  overflow: visible;
}

mjx-container[jax="SVG"][display="true"] {
  display: block;
  text-align: center;
  margin: 1em 0;
}

mjx-container[jax="SVG"][justify="left"] {
  text-align: left;
}

mjx-container[jax="SVG"][justify="right"] {
  text-align: right;
}

g[data-mml-node="merror"] > g {
  fill: red;
  stroke: red;
}

g[data-mml-node="merror"] > rect[data-background] {
  fill: yellow;
  stroke: none;
}

g[data-mml-node="mtable"] > line[data-line] {
  stroke-width: 70px;
  fill: none;
}

g[data-mml-node="mtable"] > rect[data-frame] {
  stroke-width: 70px;
  fill: none;
}

g[data-mml-node="mtable"] > .mjx-dashed {
  stroke-dasharray: 140;
}

g[data-mml-node="mtable"] > .mjx-dotted {
  stroke-linecap: round;
  stroke-dasharray: 0,140;
}

g[data-mml-node="mtable"] > svg {
  overflow: visible;
}

[jax="SVG"] mjx-tool {
  display: inline-block;
  position: relative;
  width: 0;
  height: 0;
}

[jax="SVG"] mjx-tool > mjx-tip {
  position: absolute;
  top: 0;
  left: 0;
}

mjx-tool > mjx-tip {
  display: inline-block;
  padding: .2em;
  border: 1px solid #888;
  font-size: 70%;
  background-color: #F8F8F8;
  color: black;
  box-shadow: 2px 2px 5px #AAAAAA;
}

g[data-mml-node="maction"][data-toggle] {
  cursor: pointer;
}

mjx-status {
  display: block;
  position: fixed;
  left: 1em;
  bottom: 1em;
  min-width: 25%;
  padding: .2em .4em;
  border: 1px solid #888;
  font-size: 90%;
  background-color: #F8F8F8;
  color: black;
}

foreignObject[data-mjx-xml] {
  font-family: initial;
  line-height: normal;
  overflow: visible;
}

.MathJax path {
  stroke-width: 3;
}

mjx-container[display="true"] {
  overflow: auto hidden;
}

mjx-container[display="true"] + br {
  display: none;
}
</style></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/hexo/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">CodeLeader</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">欲买桂花同载酒，终不似少年游</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/hexo/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-about"><a href="/hexo/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a></li><li class="menu-item menu-item-tags"><a href="/hexo/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签<span class="badge">19</span></a></li><li class="menu-item menu-item-categories"><a href="/hexo/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类<span class="badge">4</span></a></li><li class="menu-item menu-item-archives"><a href="/hexo/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档<span class="badge">17</span></a></li><li class="menu-item menu-item-schedule"><a href="/hexo/schedule/" rel="section"><i class="fa fa-calendar fa-fw"></i>日程表</a></li><li class="menu-item menu-item-sitemap"><a href="/hexo/sitemap.xml" rel="section"><i class="fa fa-sitemap fa-fw"></i>站点地图</a></li><li class="menu-item menu-item-commonweal"><a href="/hexo/404/" rel="section"><i class="fa fa-heartbeat fa-fw"></i>公益 404</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#java%E5%9F%BA%E7%A1%80"><span class="nav-number">1.</span> <span class="nav-text">1、Java基础</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#equals%E5%92%8Chashcode%E7%9A%84%E5%8C%BA%E5%88%AB"><span class="nav-number">1.1.</span> <span class="nav-text">&#x3D;&#x3D;，equals和hashCode的区别</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#stringstringbufferstringbuilder%E5%8C%BA%E5%88%AB"><span class="nav-number">1.2.</span> <span class="nav-text">String、StringBuffer、StringBuilder区别</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%B8%B8%E9%87%8F%E6%B1%A0"><span class="nav-number">1.3.</span> <span class="nav-text">字符串常量池</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%B5%85%E6%8B%B7%E8%B4%9D%E4%B8%8E%E6%B7%B1%E6%8B%B7%E8%B4%9D"><span class="nav-number">1.4.</span> <span class="nav-text">浅拷贝与深拷贝</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%A3%85%E7%AE%B1%E4%B8%8E%E6%8B%86%E7%AE%B1"><span class="nav-number">1.5.</span> <span class="nav-text">装箱与拆箱</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%96%B9%E6%B3%95%E9%87%8D%E5%86%99%E5%92%8C%E9%87%8D%E8%BD%BD%E7%9A%84%E5%8C%BA%E5%88%AB"><span class="nav-number">1.6.</span> <span class="nav-text">方法重写和重载的区别？</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#java%E7%A8%8B%E5%BA%8F%E5%88%9D%E5%A7%8B%E5%8C%96%E9%A1%BA%E5%BA%8F"><span class="nav-number">1.7.</span> <span class="nav-text">Java程序初始化顺序</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#io%E6%B5%81"><span class="nav-number">1.8.</span> <span class="nav-text">IO流</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#bionioaio%E7%9A%84%E5%8C%BA%E5%88%AB"><span class="nav-number">1.9.</span> <span class="nav-text">BIO、NIO、AIO的区别</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#java%E5%BA%8F%E5%88%97%E5%8C%96%E5%92%8C%E5%8F%8D%E5%BA%8F%E5%88%97%E5%8C%96"><span class="nav-number">1.10.</span> <span class="nav-text">Java序列化和反序列化</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%8F%8D%E5%B0%84%E6%9C%BA%E5%88%B6"><span class="nav-number">1.11.</span> <span class="nav-text">反射机制</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#java%E5%BC%82%E5%B8%B8%E4%BD%93%E7%B3%BB"><span class="nav-number">1.12.</span> <span class="nav-text">Java异常体系</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%BC%82%E5%B8%B8%E7%9A%84%E5%A4%84%E7%90%86%E6%96%B9%E5%BC%8F"><span class="nav-number">1.12.1.</span> <span class="nav-text">异常的处理方式</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#java%E6%B3%A8%E8%A7%A3"><span class="nav-number">1.13.</span> <span class="nav-text">Java注解</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#java%E6%B3%9B%E5%9E%8B"><span class="nav-number">1.14.</span> <span class="nav-text">Java泛型</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%B3%9B%E5%9E%8B%E7%B1%BB%E6%88%96%E6%B3%9B%E5%9E%8B%E6%8E%A5%E5%8F%A3"><span class="nav-number">1.14.1.</span> <span class="nav-text">泛型类或泛型接口</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%B3%9B%E5%9E%8B%E4%B8%8A%E9%99%90"><span class="nav-number">1.14.2.</span> <span class="nav-text">泛型上限</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%B1%BB%E5%9E%8B%E9%80%9A%E9%85%8D%E7%AC%A6"><span class="nav-number">1.14.3.</span> <span class="nav-text">类型通配符</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%B3%9B%E5%9E%8B%E6%93%A6%E9%99%A4"><span class="nav-number">1.14.4.</span> <span class="nav-text">泛型擦除</span></a></li></ol></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="别团等shy哥发育"
      src="https://codeleader.oss-cn-beijing.aliyuncs.com/site/avatar.jpg">
  <p class="site-author-name" itemprop="name">别团等shy哥发育</p>
  <div class="site-description" itemprop="description">别团等shy哥发育的博客</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/hexo/archives/">
          <span class="site-state-item-count">17</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/hexo/categories/">
        <span class="site-state-item-count">4</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/hexo/tags/">
        <span class="site-state-item-count">19</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/xiongtete0519" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;xiongtete0519" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="/hexo/xiongtete0519@gmail.com" title="E-Mail → xiongtete0519@gmail.com" rel="noopener me"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://codeleader.blog.csdn.net/" title="CSDN → https:&#x2F;&#x2F;codeleader.blog.csdn.net&#x2F;" rel="noopener me" target="_blank"><i class="fa CSDN fa-fw"></i>CSDN</a>
      </span>
  </div>

        </div>
      </div>
        <div class="back-to-top animated" role="button" aria-label="返回顶部">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://codeleader.gitee.io/hexo/2023/07/08/Java%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E5%A4%8D%E4%B9%A0/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="https://codeleader.oss-cn-beijing.aliyuncs.com/site/avatar.jpg">
      <meta itemprop="name" content="别团等shy哥发育">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="CodeLeader">
      <meta itemprop="description" content="别团等shy哥发育的博客">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="Java基础知识复习 | CodeLeader">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Java基础知识复习
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>
      

      <time title="创建时间：2023-07-08 17:14:05 / 修改时间：18:01:55" itemprop="dateCreated datePublished" datetime="2023-07-08T17:14:05+08:00">2023-07-08</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/hexo/categories/Java/" itemprop="url" rel="index"><span itemprop="name">Java</span></a>
        </span>
    </span>

  
    <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span id="busuanzi_value_page_pv"></span>
    </span>
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>2.8k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>10 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h1 id="java基础">1、Java基础</h1>
<h2 id="equals和hashcode的区别"><code>==</code>，equals和<code>hashCode</code>的区别</h2>
<ul>
<li><code>==</code>:对于基本数据类型,<code>==</code>比较的是值，对于引用数据类型，<code>==</code>比较的是内存地址。</li>
<li><code>equals</code>:对于没有重写<code>equals</code>方法的类，<code>equals</code>方法和<code>==</code>作用类似；对于重写过<code>equals</code>方法的类，<code>equals</code>比较的是值。</li>
</ul>
<span id="more"></span>
<p><code>hashCode</code>方法返回对象的散列码，返回值是int类型。散列码的作用是确定对象在哈希表中的索引位置。</p>
<blockquote>
<p>两个对象相等，则<code>hashCode</code>一定相同。</p>
<p>两个对象有相同的<code>hashCode</code>值，它们不一定相等。</p>
<p><code>hashCode()</code>方法默认是对堆上的对象产生独特值，如果没有重写<code>hashCode()</code>方法，则该类的两个对象的<code>hashCode</code>值肯定不同。</p>
</blockquote>
<h2 id="stringstringbufferstringbuilder区别">String、<code>StringBuffer</code>、<code>StringBuilder</code>区别</h2>
<ul>
<li>String类的对象是不可变的，所以线程安全，只要修改就会产生新的对象，所以频繁拼接时空消耗很大。</li>
<li><code>StringBuffer</code>和<code>StringBuilder</code>都是在原对象上操作，<code>StringBuffer</code>是线程安全的，<code>StringBuilder</code>线程不安全。</li>
</ul>
<table>
<thead>
<tr class="header">
<th style="text-align: center;">字符串</th>
<th style="text-align: center;">是否可变</th>
<th style="text-align: center;">是否安全</th>
<th style="text-align: center;">性能</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: center;">String</td>
<td style="text-align: center;">不可变</td>
<td style="text-align: center;">安全</td>
<td style="text-align: center;">低</td>
</tr>
<tr class="even">
<td style="text-align: center;"><code>StringBuffer</code></td>
<td style="text-align: center;">可变</td>
<td style="text-align: center;">安全</td>
<td style="text-align: center;">较高</td>
</tr>
<tr class="odd">
<td style="text-align: center;"><code>StringBuilder</code></td>
<td style="text-align: center;">可变</td>
<td style="text-align: center;">不安全</td>
<td style="text-align: center;">高</td>
</tr>
</tbody>
</table>
<blockquote>
<p>性能：<code>StringBuilder</code>&gt;<code>StringBuffer</code>&gt;<code>String</code></p>
</blockquote>
<h2 id="字符串常量池">字符串常量池</h2>
<p>字符串常量池位于堆内存中，专门用来存储字符串常量，可以提高内存的使用率，避免开辟多块空间存储相同的字符串，在创建字符串时JVM首先会检查字符串常量池，如果池中有该字符串，则返回它的引用，如果不存在，则实例化一个字符串放到池中，并返回其引用。</p>
<blockquote>
<p>字符串存访位置：如果使⽤常量的⽅式，该对象将被存储在常量池；如果使⽤new的⽅式，该对象将被存储在堆中。</p>
</blockquote>
<h2 id="浅拷贝与深拷贝">浅拷贝与深拷贝</h2>
<ul>
<li><strong>浅拷贝</strong>：对基本数据类型进行值传递，对引用数据类型复制一个引用指向原始引用的对象，就是复制的引用和原始引用指向同一个对象。</li>
<li><strong>深拷贝</strong>：对基本数据类型进行值传递，对引用数据类型，创建一个新的对象，并复制其内容，两个引用指向两个对象，但对象内容相同。</li>
</ul>
<figure>
<img data-src="https://codeleader.oss-cn-beijing.aliyuncs.com/site/image-20230629100728692.png" alt=""><figcaption>image-20230629100728692</figcaption>
</figure>
<h2 id="装箱与拆箱">装箱与拆箱</h2>
<ul>
<li><p><strong>装箱</strong>：将基本数据类型转换成包装类的过程。</p></li>
<li><p><strong>拆箱</strong>：将包装类转换成基本数据类型的过程。</p></li>
<li><p><strong>手动装箱</strong>：调用构造器、调用静态方法<code>valueOf</code></p></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//构造器</span></span><br><span class="line"><span class="type">int</span> intValue=<span class="number">100</span>;</span><br><span class="line">Integer obj=<span class="keyword">new</span> <span class="title class_">Integer</span>(intValue);</span><br><span class="line"><span class="comment">//静态方法</span></span><br><span class="line">Integer obj1=Integer.valueOf(intValue);</span><br></pre></td></tr></table></figure>
<ul>
<li><strong>手动拆箱</strong>：直接调用对应包装类的<code>xxValue()</code>方法即可。</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">Integer obj=<span class="keyword">new</span> <span class="title class_">Integer</span>(<span class="number">100</span>);</span><br><span class="line"><span class="type">int</span> value=obj.intValue();</span><br></pre></td></tr></table></figure>
<p><strong>自动装箱与自动拆箱</strong>(只能发生在对应的类型之间)</p>
<ul>
<li><p>自动装箱：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> intValue=<span class="number">100</span>;</span><br><span class="line">Integer obj=intValue;</span><br></pre></td></tr></table></figure></li>
<li><p>自动拆箱：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">Integer obj=<span class="keyword">new</span> <span class="title class_">Integer</span>(<span class="number">100</span>);</span><br><span class="line"><span class="type">int</span> value=obj;</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="方法重写和重载的区别">方法重写和重载的区别？</h2>
<ul>
<li><strong>方法重载</strong>：发生在同一个类中，拥有两个或更多个名称相同但参数列表(参数类型、参数个数)不同的方法，方法的重载与返回值类型无关。</li>
<li><strong>方法重写</strong>：发生在当子类继承父类时，对父类中的一些方法根据自己需求进行重写操作。</li>
</ul>
<h2 id="java程序初始化顺序">Java程序初始化顺序</h2>
<p>父类静态变量-&gt;父类静态代码块-&gt;子类静态变量-&gt;子类静态代码-&gt;父类非静态变量-&gt;父类非静态代码块-&gt;父类构造方法-&gt;子类非静态变量-&gt;子类非静态代码块-&gt;子类构造方法</p>
<h2 id="io流">IO流</h2>
<ul>
<li><code>InputStream</code>:字节输入流，以字节的方式读取数据</li>
<li><code>OutputStream</code>:字节输出流，以字节的方式输出数据</li>
<li><code>Reader</code>:字符输入流，以字符的方式读取数据</li>
<li><code>Writer</code>:字符输出流，以字符的方式输出数据</li>
</ul>
<blockquote>
<p>字节流：直接处理二进制，1字节1字节处理，适用于一切数据集，包括纯文本、doc、xls、图片、音视频等。</p>
<p>字符流：1字符1字符处理，只能处理纯文本数据。</p>
</blockquote>
<h2 id="bionioaio的区别">BIO、NIO、AIO的区别</h2>
<p><code>BIO(Blocking I/O)</code>是最传统的同步阻塞IO模型，服务器端的实现是一个连接只有一个线程处理，线程在发起请求后，回等待连接返回。</p>
<p><code>NIO(Bonblocking I/O,非阻塞IO)</code>:服务器端实现模式为一个请求一个线程，即客户端发送的请求都会注册到多路复用器上，多路复用器轮询到连接有IO请求时才启动一个线程进行处理。</p>
<p><code>AIO(Asyncchronous I/O)</code>:服务器端实现模式为一个有效请求一个线程，客户端的IO请求都是由操作系统先完成了再通知服务器用其启动线程处理。</p>
<figure>
<img data-src="https://codeleader.oss-cn-beijing.aliyuncs.com/site/image-20230706111234138.png" alt=""><figcaption>image-20230706111234138</figcaption>
</figure>
<h2 id="java序列化和反序列化">Java序列化和反序列化</h2>
<ul>
<li><p>序列化：将对象写入到IO流中。</p></li>
<li><p>反序列化：从IO流中恢复对象。</p></li>
<li><p>序列化的意义：将Java对象转换成字节数组，更加便于网络传输或存储在磁盘上，在需要时再将这些字节数组反序列化为对象。</p></li>
<li><p>实现方式：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">(<span class="number">1</span>)实现Serializable接口</span><br><span class="line">(<span class="number">2</span>)实现Externalizable接口</span><br></pre></td></tr></table></figure></li>
</ul>
<blockquote>
<p>序列化注意事项：</p>
<ul>
<li>对象的类名、实例变量会被序列化；方法、类变量、<code>transient</code>实例变量都不会被序列化。</li>
<li>想让某个变量不被序列化，可以使用<code>transient</code>修饰。</li>
<li>序列化对象的引用成员变量也必须是可序列化的，否则会报错。</li>
<li>反序列化时必须有序列化对象的<code>class</code>文件。</li>
</ul>
</blockquote>
<h2 id="反射机制">反射机制</h2>
<p><strong>反射机制</strong>是在程序运行中，对任意一个类都能获取其所有属性和方法，并且对任意对象都能调用其任意方法。这种动态获取类和对象的信息，以及动态调用对象的方法的功能被称为Java的反射机制。</p>
<p>Java获取Class对象的三种方式</p>
<ul>
<li>调用某个类的<code>getClass</code>方法</li>
<li>调用某个类的<code>class</code>属性</li>
<li>调用Class类中的<code>forName</code>静态方法</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">Person p=<span class="keyword">new</span> <span class="title class_">Person</span>();</span><br><span class="line"><span class="comment">//调用getClass方法</span></span><br><span class="line">Class c1=p.getClass();</span><br><span class="line"><span class="comment">//调用类的class属性</span></span><br><span class="line">Class c2=Person.class;</span><br><span class="line"><span class="comment">//调用Class类中的forName静态方法</span></span><br><span class="line">Class c3=Class.forName(<span class="string">"com.company"</span>)<span class="comment">//(完整包路径及名称)</span></span><br></pre></td></tr></table></figure>
<blockquote>
<p>因为一个类在<code>JVM</code>中只会有一个<code>Class</code>实例，所以对<code>c1、c2、c3</code>进行<code>equals</code>比较时返回的都是<code>true</code>。</p>
</blockquote>
<h2 id="java异常体系">Java异常体系</h2>
<p>Java中的异常主要分为Error和Exception</p>
<ul>
<li>Error:指的是Java虚拟机无法解决的严重问题，一般不编写针对性的代码进行处理。</li>
<li>Exception：指Java程序运行异常，在运行中的程序发生了程序员不期望发生的事情，可以被Java异常处理机制处理。</li>
</ul>
<figure>
<img data-src="https://codeleader.oss-cn-beijing.aliyuncs.com/site/image-20230706112049155.png" alt=""><figcaption>image-20230706112049155</figcaption>
</figure>
<ul>
<li><code>RuntimeException</code>:指在Java虚拟机正常运⾏期间抛出的异常，<code>RuntimeException</code>可以被捕获并处理，如果出现此情况，我们需要抛出异常或者 捕获并处理异常。常见的有<code>NullPointerException</code>、<code>ClassCastException</code>、 <code>ArrayIndexOutOfBoundsException</code>等</li>
<li><code>CheckedException</code>:指在编译阶段Java编译器检查<code>CheckedException</code>异常，并强制程序捕获和处理此类异常，要求程序在可能出现 异常的地⽅通过<code>try catch</code>语句块捕获异常并处理异常。常见的有由于I/O错误导致 的<code>IOException</code>、<code>SQLException</code>、<code>ClassNotFoundException</code>等。该类异常通常由于打开错误的⽂件、<code>SQL</code>语法错误、类不存在等引起。</li>
</ul>
<h3 id="异常的处理方式">异常的处理方式</h3>
<ul>
<li>抛出异常</li>
<li>使用try catch语句捕获异常</li>
</ul>
<h2 id="java注解">Java注解</h2>
<p>注解(Annotation)是Java提供的设置程序中元素的关联信息和元数据(<code>MetaData</code>)的方法，它是一个接口，程序可以通过反射获取指定程序中元素的注解对象，然后通过该注解对象获取注解中的元数据信息。</p>
<p>(1)<strong>系统预定义的基本注解</strong>：</p>
<ul>
<li><code>@Override</code>:标记某个方法是重写父类或父接口的方法，该注解只能标记在重写的方法上面。</li>
<li><code>@Deprecated</code>:标记某个程序元素(类、方法等)已过时。</li>
<li><code>@SuppressWarnings</code>:标记在需要抑制编译器警告的程序元素上。</li>
</ul>
<p><strong>(2)元注解</strong>：</p>
<ul>
<li><code>@Target</code>：限制注解的使用范围，即该注解可以用于哪些程序元素。</li>
<li><code>@Retention</code>:用来解释新声明注解的保留策略。</li>
<li><code>@Documented</code>:用于解释新声明注解用在某个包、类、方法等上面后，当使用<code>javadoc</code>工具提取文档注释生成的<code>API</code>文档时，是否将对应的注解信息也去读到<code>API</code>文档。</li>
<li><code>@Inherited</code>:用于解释新声明注解用在某个类、方法上面后是否可以被其子类继承。</li>
<li><code>@Repeatable</code>:Java 8新注解，引入重复注解机制，这样相同的注解可以在同一个地方使用多次，重复注解机制本身必须使用<code>@Repeatable</code>注解标记。</li>
</ul>
<p><strong>(3)自定义注解</strong>：</p>
<p>在Java中，注解被看作一种特殊的接口，使用<code>@interface</code>关键字进行声明。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">@元注解</span><br><span class="line">[修饰符] <span class="meta">@interface</span> 注解名{</span><br><span class="line">	返回值类型 方法名() <span class="keyword">default</span> 默认返回值</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p>例如：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Target(ElementType.METHOD)</span>	<span class="comment">//作用在方法上</span></span><br><span class="line"><span class="meta">@Retention(RetentionPolicy.RUNTIME)</span><span class="comment">//保留到运行期间</span></span><br><span class="line"><span class="keyword">public</span> <span class="meta">@interface</span> MyAnnotation {</span><br><span class="line">    String <span class="title function_">value</span><span class="params">()</span> <span class="keyword">default</span> <span class="string">"codeleader"</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<blockquote>
<p>如果注解只有一个抽象方法，建议抽象方法名为value，value名的抽象方法在使用该注解时可以省略“value=”而直接返回值。</p>
</blockquote>
<h2 id="java泛型">Java泛型</h2>
<p><code>JDK1.5</code>引入了泛型的概念，让我们在程序中可以用某种方式标识完全未知的类型，使得程序顺利编写并通过编译，的能到使用时再确定它的具体类型。泛型指的就是泛化的类型，即用<code>&lt;T&gt;</code>等形式来表示一个未确定的类型。</p>
<h3 id="泛型类或泛型接口">泛型类或泛型接口</h3>
<p>如果某个类或接口在声明时，在类名或接口名后面加了泛型，那么就称它为泛型类或泛型接口。<code>JDK1.5</code>把所有的集合类和接口都改写成了泛型类和泛型接口。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">interface</span> <span class="title class_">Iterator</span>&lt;E&gt;{</span><br><span class="line">	<span class="type">boolean</span> <span class="title function_">hasNext</span><span class="params">()</span>;</span><br><span class="line">    E <span class="title function_">next</span><span class="params">()</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h3 id="泛型上限">泛型上限</h3>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//这里T只能为Number或其子类</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Student</span>&lt;T <span class="keyword">extends</span> <span class="title class_">Number</span>&gt;{ </span><br><span class="line">    <span class="keyword">private</span> String name;</span><br><span class="line">    <span class="keyword">private</span> T score;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h3 id="类型通配符">类型通配符</h3>
<p>类型通配符用一个<code>&lt;?&gt;</code>来表示，它代表任意引用数据类型。类型通配符只能出现在使用泛型类或泛型接口来声明变量或形参时。</p>
<p>类型通配符的上限:<code>&lt;? extends 上限&gt;</code></p>
<p>类型通配符的下限：<code>&lt;? super 下限&gt;</code></p>
<h3 id="泛型擦除">泛型擦除</h3>
<p>在编码阶段使用泛型时加上的类型参数，会被编译器在编译阶段去掉，这个过程叫做泛型擦除。</p>
<blockquote>
<p>泛型主要用于编译阶段。在编译后生成的<code>Java</code>字节码文件中不包含泛型中的类型信息。例如，在编码时定义的<code>List&lt;Integer&gt;</code>和<code>List&lt;String&gt;</code>经过编译后统一为List。<code>JVM</code>读取的只是List，由泛型附加的类型信息对<code>JVM</code>来说是不可见的。</p>
</blockquote>

    </div>

    
    
    

    <footer class="post-footer">
          

<div class="post-copyright">
<ul>
  <li class="post-copyright-author">
      <strong>本文作者： </strong>别团等shy哥发育
  </li>
  <li class="post-copyright-link">
      <strong>本文链接：</strong>
      <a href="https://codeleader.gitee.io/hexo/2023/07/08/Java%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E5%A4%8D%E4%B9%A0/" title="Java基础知识复习">https://codeleader.gitee.io/hexo/2023/07/08/Java基础知识复习/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>

          <div class="post-tags">
              <a href="/hexo/tags/Java/" rel="tag"># Java</a>
              <a href="/hexo/tags/%E9%9D%A2%E8%AF%95/" rel="tag"># 面试</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/hexo/2023/03/07/%E8%93%9D%E6%A1%A5%E6%9D%AF-%E6%9C%80%E4%BC%98%E6%B8%85%E9%9B%B6%E6%96%B9%E6%A1%88/" rel="prev" title="蓝桥杯-最优清零方案">
                  <i class="fa fa-chevron-left"></i> 蓝桥杯-最优清零方案
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/hexo/2023/07/08/Java%E9%9B%86%E5%90%88%E5%A4%8D%E4%B9%A0/" rel="next" title="Java集合复习">
                  Java集合复习 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 2022 – 
  <span itemprop="copyrightYear">2024</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">别团等shy哥发育</span>
</div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
    <span title="站点总字数">81k</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">4:56</span>
  </span>
</div>
<div class="busuanzi-count">
    <span class="post-meta-item" id="busuanzi_container_site_uv">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-item" id="busuanzi_container_site_pv">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>

<!-- <br /> -->
<!-- 网站运行时间的设置 -->
<span id="timeDate">载入天数...</span>
<!-- <span id="times">载入时分秒...</span> -->
<script>
    var now = new Date();
    function createtime() {
        var grt= new Date("11/17/2022 8:00:00");//此处修改你的建站时间或者网站上线时间
        now.setTime(now.getTime()+250);
        days = (now - grt ) / 1000 / 60 / 60 / 24; dnum = Math.floor(days);
        hours = (now - grt ) / 1000 / 60 / 60 - (24 * dnum); hnum = Math.floor(hours);
        if(String(hnum).length ==1 ){hnum = "0" + hnum;} minutes = (now - grt ) / 1000 /60 - (24 * 60 * dnum) - (60 * hnum);
        mnum = Math.floor(minutes); if(String(mnum).length ==1 ){mnum = "0" + mnum;}
        seconds = (now - grt ) / 1000 - (24 * 60 * 60 * dnum) - (60 * 60 * hnum) - (60 * mnum);
        snum = Math.round(seconds); 
        if(String(snum).length ==1 ){snum = "0" + snum;}
        // var times = document.getElementById("times").innerHTML = hnum + " 小时 " + mnum + " 分 " + snum + " 秒";
        document.getElementById("timeDate").innerHTML = "本站已安全运行 "+dnum+" 天 "+hnum + " 小时 " + mnum + " 分 " + snum + " 秒";
    }
setInterval("createtime()",250);
</script>

    </div>
  </footer>

  

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/hexo/js/comments.js"></script><script src="/hexo/js/utils.js"></script><script src="/hexo/js/motion.js"></script><script src="/hexo/js/next-boot.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/hexo/js/third-party/search/local-search.js"></script>




  <script src="/hexo/js/third-party/pace.js"></script>

  
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>




  

  <script class="next-config" data-name="enableMath" type="application/json">true</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/hexo/js/third-party/math/mathjax.js"></script>



</body>
</html>
